
#ifndef  RF_LOGSYS_H
#define RF_LOGSYS_H
#include <string>
#include <vector>
#include <list>

using namespace std;

#ifndef DATETIMEBUFFER_MAX
#define DATETIMEBUFFER_MAX	25 //2010-03-03 12:00:00:000
#endif


#ifndef LOGBUFFER_MAX
#define LOGBUFFER_MAX	    256
#endif//LOGBUFFER_MAX

#ifndef NAME_MAX
#define NAME_MAX			255		
#endif 

class MyLock
{
public:
	MyLock(void);
	~MyLock(void);

	void On();
	void Off();

private:
	CRITICAL_SECTION m_cs;
};


class LogDateDir{
public:
	LogDateDir();
	LogDateDir( char *pStrDateDirName );
	~LogDateDir();
	void SetLogDateDir( char *pStrDateDirName  );
private:
	char strDateDirName[DATETIMEBUFFER_MAX];
};

typedef vector< LogDateDir*> LogDirVector;



class LogWriteBuffer{

public:
	LogWriteBuffer();
	LogWriteBuffer( char *pStrFileName,
					char *pStrFileTitle,
					char *pStrDateDir,
					char *pStrWriteContent );
	~LogWriteBuffer();

	int Set_LogWriteBufferData( char *pStrFileName,
								char *pStrFileTitle,
								char *pStrDateDir,
								char *pStrWriteContent) ;

private:
	char strFileName[NAME_MAX];
	char strDateDir[NAME_MAX];
	char strFileTitle[NAME_MAX];
	char strWriteBuffer[LOGBUFFER_MAX];
};

typedef list<LogDateDir *> WriteBufferList;

class RF_LogSys{

public:
	RF_LogSys();
	~RF_LogSys();
public:
	int    insert_AscendingSortDateDirQueue( char *pNewDateDir );
private:
	bool   LogSys_FromateLocalTimeToString( LPTSTR  strTime );
	bool   LogSys_GetLocalTimeToFileNameString( LPTSTR  strTime);
	UINT   LogSys_WorkerThreadProc( LPVOID pParam );
private:
	string				m_homePath;

	LogDirVector		m_dirVector;
	MyLock				m_dirLock;

	WriteBufferList		m_bufferList;
	MyLock				m_listLock;
};
#endif